{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6c96e1e7",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "os.environ['CUDA_VISIBLE_DEVICES'] = '0'\n",
    "os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c013d091",
   "metadata": {},
   "outputs": [],
   "source": [
    "from transformers import AutoTokenizer, AutoModelForCausalLM, TextStreamer\n",
    "from peft import LoraConfig, get_peft_model, AutoPeftModelForCausalLM, PeftModel\n",
    "import torch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "34f8cc39",
   "metadata": {},
   "outputs": [],
   "source": [
    "tokenizer = AutoTokenizer.from_pretrained('unsloth/Llama-3.2-3B-Instruct')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f6d2bdcb",
   "metadata": {},
   "outputs": [],
   "source": [
    "streamer = TextStreamer(tokenizer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "7a5be3ef",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Some weights of LlamaForCausalLM were not initialized from the model checkpoint at unsloth/Llama-3.2-3B-Instruct and are newly initialized: ['lm_head.weight']\n",
      "You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n"
     ]
    }
   ],
   "source": [
    "ori_model = AutoModelForCausalLM.from_pretrained(\n",
    "    'unsloth/Llama-3.2-3B-Instruct', tie_word_embeddings=False\n",
    ").cuda()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "4220fb72",
   "metadata": {},
   "outputs": [],
   "source": [
    "ori_model.lm_head.weight.data = ori_model.model.embed_tokens.weight.data.clone()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c2ab6c40",
   "metadata": {},
   "outputs": [],
   "source": [
    "state_dict = ori_model.state_dict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "117dd77b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "96cc179daa674dce8e5c143b067d7fe5",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Fetching 4 files:   0%|          | 0/4 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from huggingface_hub import snapshot_download\n",
    "\n",
    "lora = snapshot_download(\n",
    "    repo_id=\"mesolitica/lora-embedding-256-llama3.2-3b-multipack\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "314486b6",
   "metadata": {},
   "outputs": [],
   "source": [
    "from safetensors import safe_open\n",
    "\n",
    "f = safe_open(f\"{lora}/adapter_model.safetensors\", framework=\"pt\", device=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f75d1173",
   "metadata": {},
   "outputs": [],
   "source": [
    "keys = f.keys()\n",
    "keys = sorted(list(set([k.split('.lora')[0] for k in keys if '.lora' in k])))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e730eea3",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████████████████████████████████████████████████████████████████████████████████████| 198/198 [00:00<00:00, 478.95it/s]\n"
     ]
    }
   ],
   "source": [
    "from tqdm import tqdm\n",
    "\n",
    "for k in tqdm(keys):\n",
    "    k_ori = k.replace('base_model.model.', '') + '.weight'\n",
    "    if 'embed_tokens' in k:\n",
    "        post_A = '.lora_embedding_A'\n",
    "        post_B = '.lora_embedding_B'\n",
    "    else:\n",
    "        post_A = '.lora_A.weight'\n",
    "        post_B = '.lora_B.weight'\n",
    "    A = k + post_A\n",
    "    B = k + post_B\n",
    "    \n",
    "    W = state_dict[k_ori]\n",
    "    if 'embed_tokens' not in k:\n",
    "        W = W.t()\n",
    "        \n",
    "    A = f.get_tensor(A)\n",
    "    B = f.get_tensor(B)\n",
    "    with torch.no_grad():\n",
    "        W.addmm_(A.t(), B.t(), alpha = 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "626a66b2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# model = AutoPeftModelForCausalLM.from_pretrained(\n",
    "#     'mesolitica/lora-embedding-256-llama3.2-3b-multipack', torch_dtype=torch.bfloat16,\n",
    "# )\n",
    "# _ = model.cuda()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "443a56bb",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/husein/.local/lib/python3.10/site-packages/transformers/generation/configuration_utils.py:601: UserWarning: `do_sample` is set to `False`. However, `temperature` is set to `0.0` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `temperature`.\n",
      "  warnings.warn(\n",
      "/home/husein/.local/lib/python3.10/site-packages/transformers/generation/configuration_utils.py:606: UserWarning: `do_sample` is set to `False`. However, `top_p` is set to `0.95` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `top_p`.\n",
      "  warnings.warn(\n",
      "The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
      "Setting `pad_token_id` to `eos_token_id`:None for open-end generation.\n",
      "The attention mask is not set and cannot be inferred from input because pad token is same as eos token. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n",
      "\n",
      "Cutting Knowledge Date: December 2023\n",
      "Today Date: 19 Oct 2024\n",
      "\n",
      "<|eot_id|><|start_header_id|>user<|end_header_id|>\n",
      "\n",
      "ape isu dengan "
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Starting from v4.46, the `logits` model output will have the same type as the model (except at train time, where it will always be FP32)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "najib<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n",
      "\n",
      "Najib Razak, yang berkhidmat sebagai Perdana Menteri Malaysia dari 2009 hingga 2018, telah menjadi subjek pelbagai kontroversi dan skandal semasa memegang jawatan. Berikut adalah beberapa isu utama yang berkaitan dengannya:\n",
      "\n",
      "1. Skandal 1MDB: Najib Razak terlibat dalam skandal kewangan besar-besaran yang melibatkan dana pelaburan negara 1Malaysia Development Berhad (1MDB). Jabatan Kehakiman AS mendakwa bahawa lebih $4.5 bilion telah diselewengkan daripada 1MDB, dengan beberapa dana mengalir ke akaun bank peribadi Najib. Najib secara konsisten menafikan sebarang salah laku, tetapi dia didakwa dengan pelbagai pertuduhan rasuah, pengubahan wang haram, dan penyalahgunaan kuasa di Malaysia.\n",
      "\n",
      "2. Penindasan kebebasan bersuara dan perhimpunan: Semasa memegang jawatan, Najib Razak dikritik kerana pendekatannya yang keras terhadap kebebasan bersuara dan perhimpunan. Kerajaannya dituduh menggunakan pelbagai taktik untuk menyekat perbezaan pendapat, termasuk penggunaan Akta Hasutan, undang-undang era penjajah yang menjenayahkan ucapan yang dianggap menghasut atau berkemungkinan menyebabkan gangguan awam.\n",
      "\n",
      "3. Pengendalian pandemik COVID-19: Pengendalian kerajaan Najib Razak terhadap pandemik COVID-19 juga menjadi subjek kritikan. Pengkritik menuduhnya lambat bertindak balas dan tidak mencukupi dalam menyediakan bantuan kepada mereka yang terjejas oleh pandemik. Selain itu, terdapat dakwaan rasuah dan kronisme dalam pemberian kontrak dan sumber untuk menangani pandemik.\n",
      "\n",
      "4. Rasuah dan kronisme: Najib Razak telah dituduh rasuah dan kronisme selama bertahun-tahun, terutamanya berkaitan dengan pemberian kontrak kerajaan dan pemberian sumber. Pengkritik menuduhnya\n"
     ]
    }
   ],
   "source": [
    "d = [\n",
    "    {'role': 'user', 'content': 'ape isu dengan najib'}\n",
    "]\n",
    "\n",
    "inputs = tokenizer.apply_chat_template(d, return_tensors = 'pt').to('cuda')\n",
    "generate_kwargs = dict(\n",
    "    input_ids=inputs,\n",
    "    max_new_tokens=512,\n",
    "    top_p=0.95,\n",
    "    top_k=50,\n",
    "    temperature=0.0,\n",
    "    do_sample=False,\n",
    "    repetition_penalty=1.05,\n",
    "    streamer=streamer\n",
    ")\n",
    "generation_output = ori_model.generate(**generate_kwargs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "4aa125bb",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/husein/.local/lib/python3.10/site-packages/transformers/generation/configuration_utils.py:601: UserWarning: `do_sample` is set to `False`. However, `temperature` is set to `0.9` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `temperature`.\n",
      "  warnings.warn(\n",
      "The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
      "Setting `pad_token_id` to `eos_token_id`:None for open-end generation.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n",
      "\n",
      "Cutting Knowledge Date: December 2023\n",
      "Today Date: 19 Oct 2024\n",
      "\n",
      "<|eot_id|><|start_header_id|>user<|end_header_id|>\n",
      "\n",
      "camne nk code react, reply in jawi<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n",
      "\n",
      "اونتوق مڠکودکن رياکت، اندا بوليه ممولاکن دڠن مماسڠ ڤاکيج يڠ دڤرلوکن. بريکوت اداله چارا اونتوق منچاري دان مماسڠ ڤاکيج يڠ دڤرلوکن:\n",
      "\n",
      "١. Node.js (ۏرسي ٨ اتاو لبيه تيڠݢي)\n",
      "٢. npm (Node Package Manager)\n",
      "\n",
      "جالنکن ارهن برايکوت اونتوق مماسڠ ڤاکيج يڠ دڤرلوکن:\n",
      "\n",
      "```\n",
      "npm install react react-dom\n",
      "```\n",
      "\n",
      "سکارڠ، چيڤتا فايل بارو يڠ دڤڠݢيل `App.js` دان تمبهکن کود برايکوت:\n",
      "\n",
      "```jsx\n",
      "import React from'react';\n",
      "\n",
      "function App() {\n",
      "  return (\n",
      "    <div className=\"App\">\n",
      "      <h1>Hello World!</h1>\n",
      "    </div>\n",
      "  );\n",
      "}\n",
      "\n",
      "export default App;\n",
      "```\n",
      "\n",
      "دالم کود اين، کامي مڠايمڤورت کبرݢنتوڠن `React` دري ڤاکيج `react`. کمودين، کامي منتوکن فوڠسي `App` يڠ مڠمباليکن ايليمن `<div>` يڠ مڠندوڠي تاجوق \"Hello World!\".\n",
      "\n",
      "اخير سکالي، کامي مڠيکسڤورت فوڠسي `App` سباݢاي اليرن اوتام.\n",
      "\n",
      "اونتوق مڠوجي اڤليکاسي، جالنکن ارهن برايکوت:\n",
      "\n",
      "```\n",
      "npm start\n",
      "```\n",
      "\n",
      "اين اکن ممبوک ڤلاير ويب دان مڽدياکن اڤليکاسي رياکت اندا. اندا بوليه مڠوبه کود دالم فايل `App.js` اونتوق منمبه لبيه باڽق ايليمن دان لوݢيک اڤابيلا دڤرلوکن.<|eot_id|>\n"
     ]
    }
   ],
   "source": [
    "d = [\n",
    "    {'role': 'user', 'content': 'camne nk code react, reply in jawi'}\n",
    "]\n",
    "\n",
    "inputs = tokenizer.apply_chat_template(d, return_tensors = 'pt').to('cuda')\n",
    "generate_kwargs = dict(\n",
    "    input_ids=inputs,\n",
    "    max_new_tokens=512,\n",
    "    top_p=0.95,\n",
    "    top_k=50,\n",
    "    temperature=0.9,\n",
    "    do_sample=False,\n",
    "    repetition_penalty=1.1,\n",
    "    streamer=streamer\n",
    ")\n",
    "generation_output = ori_model.generate(**generate_kwargs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "a0495b30",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
      "Setting `pad_token_id` to `eos_token_id`:None for open-end generation.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n",
      "\n",
      "Cutting Knowledge Date: December 2023\n",
      "Today Date: 19 Oct 2024\n",
      "\n",
      "<|eot_id|><|start_header_id|>user<|end_header_id|>\n",
      "\n",
      "camne nk code react, reply in sabah<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n",
      "\n",
      "Bah, kunuk sia mau kasi tau macam mana mo bikin kod React dalam Bahasa Kebangsaan Sunda. Tingu saja la ni contoh kode yang boleh kamurang guna:\n",
      "\n",
      "```jsx\n",
      "import React from'react';\n",
      "// Import anu-anu lain kalau perlu\n",
      "\n",
      "function KomponenApaSia() {\n",
      "    // Kod komponen di sini\n",
      "}\n",
      "\n",
      "const Pengawal = () => (\n",
      "    <div>\n",
      "        {/* Susun barang-barang di situlah */}\n",
      "        \n",
      "    }\n",
      ");\n",
      "\n",
      "export default Pengawal;\n",
      "```\n",
      "\n",
      "Dalam kes tersebut tu `KomponenApa`, ada fungsi untuk apa-apa benda yang mungkin mo kita laksana.\n",
      "\n",
      "Macam `Pengawal` pun sama ja bah, tapi ia macam pengurus utama yang ambil alih semua masalah-masalah besar dengan urus keadaannya pakai ciri-ciri 'State' dari pustaka'middleware'.\n",
      "\n",
      "Jadi tugas kamu dorangan nanti sekarang lah supaya bolek ubahkan konteks tertentu ikut permintaan aplikasi baru atau tambahan (macam 'Komen', bukan\n"
     ]
    }
   ],
   "source": [
    "d = [\n",
    "    {'role': 'user', 'content': 'camne nk code react, reply in sabah'}\n",
    "]\n",
    "\n",
    "inputs = tokenizer.apply_chat_template(d, return_tensors = 'pt').to('cuda')\n",
    "generate_kwargs = dict(\n",
    "    input_ids=inputs,\n",
    "    max_new_tokens=256,\n",
    "    top_p=0.95,\n",
    "    top_k=50,\n",
    "    temperature=0.9,\n",
    "    do_sample=True,\n",
    "    repetition_penalty=1.3,\n",
    "    streamer=streamer\n",
    ")\n",
    "generation_output = ori_model.generate(**generate_kwargs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "f33a1242",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
      "Setting `pad_token_id` to `eos_token_id`:None for open-end generation.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n",
      "\n",
      "Cutting Knowledge Date: December 2023\n",
      "Today Date: 19 Oct 2024\n",
      "\n",
      "<|eot_id|><|start_header_id|>user<|end_header_id|>\n",
      "\n",
      "camne nk selesaikan masalah hutang negara, reply in mandarin<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n",
      "\n",
      "解决马来西亚的国家债务问题需要采取多方面的方法，包括财政改革、经济增长和投资。以下是一些可能的策略：\n",
      "\n",
      "1. 改革财政制度：马来西亚可以通过减少政府支出、提高收入和实施更有效的公共部门管理来改善其财政状况。这可能涉及缩小政府的规模、减少不必要的公共项目以及促进私营部门的增长。\n",
      "2. 增加税收：马来西亚可以通过增加税收并提高税收效率来增加收入。这可能涉及对富裕个人和公司征收更高的税率，以及实施新的税收机制，如销售税或消费税。\n",
      "3. 投资长期计划：马来西亚可以通过投资基础设施、教育和医疗保健等长期计划来创造就业机会并刺激经济增长。这可能涉及向私营部门提供补贴以鼓励投资，也可能涉及为这些领域进行大量公共投资。\n",
      "4. 实施财政监管改革：马来西亚可以通过实施财政监管改革来提高其财政绩效。这可能涉及建立独立的财政机构来监督政府财政，并实施透明度和问责制措施。\n",
      "5. 与国际伙伴合作：马来西亚可以与国际组织和其他国家合作解决国家债务问题。这可能涉及寻求援助和支持，或参与国际金融机构的举措。\n",
      "\n",
      "值得注意的是，这些只是马来西亚可以采取的一些潜在策略，解决国家债务问题是一个复杂而有挑战性的任务，需要采取全面和协调的方法。<|eot_id|>\n"
     ]
    }
   ],
   "source": [
    "d = [\n",
    "    {'role': 'user', 'content': 'camne nk selesaikan masalah hutang negara, reply in mandarin'}\n",
    "]\n",
    "\n",
    "inputs = tokenizer.apply_chat_template(d, return_tensors = 'pt').to('cuda')\n",
    "generate_kwargs = dict(\n",
    "    input_ids=inputs,\n",
    "    max_new_tokens=1024,\n",
    "    top_p=0.95,\n",
    "    top_k=50,\n",
    "    temperature=0.2,\n",
    "    do_sample=True,\n",
    "    repetition_penalty=1.1,\n",
    "    streamer=streamer\n",
    ")\n",
    "generation_output = ori_model.generate(**generate_kwargs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "d640eab3",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
      "Setting `pad_token_id` to `eos_token_id`:None for open-end generation.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n",
      "\n",
      "Cutting Knowledge Date: December 2023\n",
      "Today Date: 19 Oct 2024\n",
      "\n",
      "<|eot_id|><|start_header_id|>user<|end_header_id|>\n",
      "\n",
      "camne nk code react<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n",
      "\n",
      "Untuk memulakan, anda perlu mempunyai persekitaran React yang dipasang pada komputer atau mesin anda. Berikut adalah langkah-langkah asas untuk menulis kod React:\n",
      "\n",
      "1. **Pasang Node.js dan npm**: Pastikan anda telah memasang Node.js (versi 14 ke atas) dan npm (Node Package Manager) di komputer anda.\n",
      "\n",
      "2. **Cipta projek baru dengan `create-react-app`**:\n",
      "   - Buka terminal atau command prompt.\n",
      "   - Jalankan arahan berikut untuk mencipta projek React baru menggunakan `create-react-app`:\n",
      "     ```\n",
      "     npx create-react-app nama-projek-anda\n",
      "     ```\n",
      "     Gantikan \"nama-projek-anda\" dengan nama sebenar untuk projek anda.\n",
      "\n",
      "3. **Navigasi ke direktori projek**:\n",
      "   - Selepas penciptaan, navigasi ke direktori projek dengan menjalankan:\n",
      "     ```\n",
      "     cd nama-projek-anda\n",
      "     ```\n",
      "\n",
      "4. **Mulakan aplikasi React**:\n",
      "   - Untuk memulakan aplikasi, jalankan arahan berikut:\n",
      "     ```\n",
      "     npm start\n",
      "     ```\n",
      "     Ini akan membuka pelayan pembangunan dalam pelayar web anda.\n",
      "\n",
      "5. **Tulis kod React**:\n",
      "   - Dalam fail `App.js`, `index.js`, atau mana-mana fail lain yang sesuai, anda boleh menulis kod React anda.\n",
      "   - Contoh mudah untuk menghasilkan elemen HTML dan CSS dalam React adalah seperti berikut:\n",
      "     ```jsx\n",
      "     import React from react';\n",
      "\n",
      "     function HelloWorld() {\n",
      "       return (\n",
      "         <div>\n",
      "           <h1>Hello World!</h1>\n",
      "         </div>\n",
      "       );\n",
      "     }\n",
      "\n",
      "     export default HelloWorld;\n",
      "     ```\n",
      "\n",
      "6. **Import dan gunakan komponen**:\n",
      "   - Jika anda ingin menggunakan komponen lain dari projek anda, anda boleh mengimportnya dengan menggunakan `import KomponenDariProyekAnda dari './NamaFailKomponen';`.\n",
      "\n",
      "7. **Uji dan ujian kod**:\n",
      "   - Gunakan alat seperti Jest untuk ujian unit dan Enzyme untuk ujian integrasi.\n",
      "\n",
      "8. **Pengoptimuman dan penyelesaian masalah**:\n",
      "   - Uji semula kod anda selepas membuat perubahan, dan pastikan ia berfungsi seperti yang diharapkan.\n",
      "\n",
      "9. **Kompilasi dan minifikasi kod**:\n",
      "   - Untuk pengeluaran, anda mungkin perlu mengkompilasi dan mengminifikasikan kod anda menggunakan Webpack atau perpustakaan lain.\n",
      "\n",
      "10. **Penyediaan untuk pengedaran**:\n",
      "    - Setelah kod anda siap, anda boleh menyediakannya untuk pengedaran melalui platform seperti GitHub Pages atau hosting sendiri.\n",
      "\n",
      "Ingat bahawa ini hanyalah titik permulaan, dan terdapat banyak lagi konsep dan teknik yang perlu dipelajari untuk menjadi pakar dalam React. Selain itu, pastikan anda memahami konsep seperti komponen, keadaan, hook, dan reaktifiti sebagai asas utama untuk membangunkan aplikasi React yang canggih.<|eot_id|>\n"
     ]
    }
   ],
   "source": [
    "d = [\n",
    "    {'role': 'user', 'content': 'camne nk code react'}\n",
    "]\n",
    "\n",
    "inputs = tokenizer.apply_chat_template(d, return_tensors = 'pt').to('cuda')\n",
    "generate_kwargs = dict(\n",
    "    input_ids=inputs,\n",
    "    max_new_tokens=1024,\n",
    "    top_p=0.95,\n",
    "    top_k=50,\n",
    "    temperature=0.2,\n",
    "    do_sample=True,\n",
    "    repetition_penalty=1.1,\n",
    "    streamer=streamer\n",
    ")\n",
    "generation_output = ori_model.generate(**generate_kwargs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "d077bcc3",
   "metadata": {},
   "outputs": [],
   "source": [
    "ori_model = ori_model.to(torch.bfloat16)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "bf2223dc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "89d12c45d8a64d3caf25b9aad3137c29",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "README.md:   0%|          | 0.00/673 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "6d81767c1bc74451a45cb7b8d27dafd9",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "model-00001-of-00002.safetensors:   0%|          | 0.00/4.97G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4b75f8771cd94795bc7955900add0c08",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "model-00002-of-00002.safetensors:   0%|          | 0.00/2.25G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e99ff290440640bfa3679d34138ab5c9",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Upload 2 LFS files:   0%|          | 0/2 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "CommitInfo(commit_url='https://huggingface.co/mesolitica/malaysian-Llama-3.2-3B-Instruct/commit/d85cca4fb40612d5f3a80baeea5ccaed193b93b3', commit_message='Upload LlamaForCausalLM', commit_description='', oid='d85cca4fb40612d5f3a80baeea5ccaed193b93b3', pr_url=None, pr_revision=None, pr_num=None)"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ori_model.push_to_hub('mesolitica/malaysian-Llama-3.2-3B-Instruct')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "615cb675",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "python3.10",
   "language": "python",
   "name": "python3.10"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
